Creating a UPS Zone database

To convert the "Zone Chart" from UPS format to MGI format.

First you need the Zone Chart from UPS.
http://www.ups.com/using/software/currentrates/rates_in_us.html#zones

Enter your zipcode that you will be shipping from and download the file in comma separated format.
You should get a file named something like 300.csv where the '300' is the first three digits of the zipcode.

The contents of the file will look something like this in BBedit. You may have to replace all \n with \r.

"ZONE CHART"
"UPS Ground/UPS 3 Day Select/UPS 2nd Day Air/UPS 2nd Day Air A.M./UPS Next Day Air Saver/UPS Next Day Air"

"For shipments originating in ZIP Codes 300-01 to 303-99.  To determine zone"
"take the first three digits of the receiver's ZIP Code and refer to the chart below:"

"ZONES"
Dest. ZIP,Ground,3 Day Select,2nd Day Air,2nd Day Air A.M.,Next Day Air Saver,Next Day Air

004-005,5,305,205,245,135,105
006-007,-,-,225,-,-,125
008,-,-,[1],-,-,[1]
009,-,-,225,-,-,125
010-041,5,305,205,245,135,105
.
.
.
.
967-968,-,-,[2],-,-,[2]
969,-,-,[1],-,-,[1]
970-994,8,308,208,248,138,108
995-999,-,-,[3],-,-,[3]
,,,,,,


"[1] For Virgin Islands, Guam, Marshall Islands, etc., please refer to the Worldwide Rate and Zone information."

"[2] For Hawaii, the following Postal Codes are Zone 124 for Next Day Air and Zone 224 for 2nd Day Air:"
96701,96706,96707,96709,96712,96717,96730,96731,96734,96744,96759,96762,96782,96786,96789,96791,96792,96795,96797,96801

Remove stuff from the top and the bottom to make it look like this:

004-005,5,305,205,245,135,105
006-007,-,-,225,-,-,125
008,-,-,[1],-,-,[1]
009,-,-,225,-,-,125
010-041,5,305,205,245,135,105
.
.
.
.
967-968,-,-,[2],-,-,[2]
969,-,-,[1],-,-,[1]
970-994,8,308,208,248,138,108
995-999,-,-,[3],-,-,[3]

Now in BBedit in GREP mode replace ^([\d]+[^,-])(,) with \1-\1,
Now in BBedit in GREP mode replace ^([\d]+)- with \1\t
Now in BBedit in NORMAL mode replace , with \t

Now prepend this to the beginning of the file. Make sure that you have tabs in the right spots.


!Generated by MGI!
(T,5,X)Dest-ZIP1 (T,5,X)Dest-ZIP2 (T,5,X)Ground (T,5,X)3DaySelect (T,5,X)2ndDayAir (T,5,X)2ndDayAirAM (T,5,X)NextDayAirSaver (T,5,X)NextDayAir

You now have a Zone Table ready to import into an MGI database.

You can search this database like this:

<mgiSet name="search">Dest-ZIP1<='<mgiGet name="zipcode">' AND Dest-ZIP2>='<mgiGet name="zipcode">'</mgiSet><BR>
<mgiSearchDatabase databaseName="zones-db" searchString={mgiGet name="search"}><BR>
  <mgiSet name="ground">Zone&mgiDBFieldGround;</mgiSet><BR>
  <mgiSet name="2da">Zone&mgiDBField2ndDayAir;</mgiSet><BR>
</mgiSearchDatabase><BR>

Enjoy,
Ted Burger