Skip to content

Instantly share code, notes, and snippets.

@hexfusion
Created March 12, 2014 19:25
Show Gist options
  • Save hexfusion/9514389 to your computer and use it in GitHub Desktop.
Save hexfusion/9514389 to your computer and use it in GitHub Desktop.
package Interchange6::Schema::Populate::UPSZone;;
use strict;
use warnings;
use Moo;
use Business::UPS;
=head Description
This data is taken from the UPS website and uses the following format
['range_begin','range_end']
http://www.ups.com/content/us/en/shipping/cost/zones/continental_us.html
=cut
sub records {
my ($self, $shipment_methods) = @_;
my @ups_zone_dom = (
['00400', '00599'],['00600', '00799'],['00900', '00999'],
['01000', '01399'],['01400', '04299'],['04300', '04999'],
['05000', '05199'],['05200', '05399'],['04400', '05999'],
['06000', '06199'],['06200', '06599'],['06600', '07999'],
['08000', '08499'],['08500', '08999'],['10000', '11899'],
['11900', '11999'],['12000', '12899'],['12900', '12999'],
['13000', '14299'],['14300', '14399'],['14400', '14699'],
['14700', '14799'],['14800', '14999'],['15000', '16599'],
['16600', '17299'],['17300', '17499'],['17500', '18999'],
['19000', '19299'],['19300', '19699'],['19700', '22999'],
['23000', '25399'],['25400', '25499'],['25500', '25999'],
['26000', '26099'],['26100', '26299'],['26300', '26599'],
['26600', '26699'],['26700', '26899'],['27000', '28899'],
['28900', '29299'],['29300', '29399'],['29400', '29499'],
['29300', '29399'],['29400', '29499'],['29500', '29599'],
['29600', '29699'],['29700', '29799'],['29800', '32499'],
['32500', '32599'],['32600', '32999'],['33000', '33999'],
['32600', '32999'],['33000', '33999'],['34100', '34199'],
['34200', '34299'],['34400', '34499'],['34600', '34699'],
['34700', '34799'],['34900', '34999'],['35000', '36499'],
['36500', '36699'],['36700', '37599'],['37600', '37999'],
['38000', '38699'],['38700', '38799'],['38800', '38999'],
['39000', '39299'],['39300', '39399'],['39400', '39699'],
['39700', '39999'],['40000', '41899'],['42000', '42499'],
['42500', '43899'],['43900', '43999'],['44000', '44399'],
['44400', '44799'],['44800', '47499'],['47500', '47899'],
['47900', '49799'],['49800', '50999'],['51000', '51299'],
['51300', '51499'],['51500', '51599'],['51600', '52899'],
['53000', '53499'],['53500', '56499'],['56500', '56599'],
['56600', '56699'],['56700', '58899'],['59000', '59699'],
['59700', '59999'],['60000', '64799'],['64800', '64899'],
['64900', '66399'],['66400', '72299'],['72300', '72599'],
['72600', '73299'],['73300', '73399'],['73400', '76799'],
['76800', '76999'],['77000', '77899'],['77900', '79799'],
['77000', '77899'],['77900', '79799'],['79800', '79999'],
['80000', '83199'],['83200', '86499'],['86500', '87999'],
['88000', '88099'],['88100', '88499'],['88500', '96199'],
['97000', '98699'],['98800', '99499'],
);
my $home = '13783';
my @zones;
my $postal_range_start;
my $postal_range_end;
foreach ( @ups_zone_dom ) {
$postal_range_start = @$_[0];
$postal_range_end = @$_[1];
my (undef,$zone) = getUPS($shipment_methods->code, $home, $postal_range_start, '50');
if (!$zone) {
$zone = undef;
}
push @zones, {'country_iso_code' => 'US', 'shipment_methods_id' => $shipment_methods->id,
'postal_range_start' => $postal_range_start, 'postal_range_end' => $postal_range_end, 'zone' => $zone };
}
return \@zones;
}
sub records2 {
my ($self, $product_code, $max_weight, $postal_range_start, $zone_id) = @_;
my $max = '150';
my @rates;
my @array = ("01"..$max);
my $home = '13783';
foreach my $weight (@array) {
my ($price, undef, undef) = getUPS($product_code, $home, $postal_range_start, $weight);
push @rates, {'shipment_carrier_zones_id' => $zone_id, 'weight' => $weight, 'price' => $price};
}
return \@rates;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment