Use this script to change the carrier for any order that's shipping to a ZIP code that's included in FedEx's "Zone 2".


For example, in the script below we are using a hash map which includes the first 3 digits of all possible ZIP codes in Zone 2.  Whenever an order comes across with a Ship To ZIP code whose first 3 digits matches one of the ZIP codes in zone 2, change the carrier to carrierId 7000 (FedEx Ground).  If it doesn't match, therefore not being in zone 2, change the carrier to carrierId 7002 (FedEx 2-Day).  


This script can be adapted to include other zones and carriers.

// Initialize mySet to a hash map with all the zone 2 ZIP codes
var mySet = {'005': true, '012': true, '060': true, '061': true, '062': true, '063': true, '064': true, '065': true, '066': true, '067': true, '068': true, '069': true, '070': true, '071': true, '072': true, '073': true, '074': true, '075': true, '076': true, '077': true, '078': true, '079': true, '080': true, '081': true, '082': true, '083': true, '084': true, '085': true, '086': true, '087': true, '088': true, '089': true, '090': true, '091': true, '092': true, '093': true, '094': true, '095': true, '096': true, '097': true, '098': true, '099': true, '100': true, '101': true, '102': true, '103': true, '104': true, '105': true, '106': true, '107': true, '108': true, '109': true, '110': true, '111': true, '112': true, '113': true, '114': true, '115': true, '116': true, '117': true, '118': true, '119': true, '124': true, '125': true, '126': true, '127': true, '137': true, '138': true, '139': true, '168': true, '169': true, '170': true, '171': true, '172': true, '173': true, '174': true, '175': true, '176': true, '177': true, '178': true, '179': true, '180': true, '181': true, '182': true, '183': true, '184': true, '185': true, '186': true, '187': true, '188': true, '189': true, '190': true, '191': true, '192': true, '193': true, '194': true, '195': true, '196': true, '197': true, '198': true, '199': true, '200': true, '201': true, '202': true, '203': true, '204': true, '205': true, '206': true, '207': true, '208': true, '209': true, '210': true, '211': true, '212': true, '214': true, '216': true, '217': true, '218': true, '219': true, '220': true, '221': true, '222': true, '223': true};
var zipCode = order.shipToZip;
var zipCodeFirstThree = zipCode.substring(0,3);

utils.log("The first 3 digits of the Ship To ZIP are " + zipCodeFirstThree);
utils.log("mySet[zipCodeFirstThree] = " + mySet[zipCodeFirstThree]);

// If the first 3 digits of the shipTo ZIP code match any of the values in mySet, change the carrier to FedEx Ground
if(mySet[zipCodeFirstThree])
{
    order.carrierId = 7000;
}

// If the first 3 digits of the shipTo ZIP code didn't match the values in mySet, change the carrier to FedEx 2nd day.
else
{
    order.carrierId = 7002;
}

infoplusApi.update("order", order);