Fetching Rates¶
There are two types of rates calculations that can be requested with RocketShipIt:
Since these requests take about the same time we recommend always fetching all rates and filtering only the ones you are interested in.
Fetching all detailed rates for a given address¶
To get rates for all available services you simply create a new rate object, set appropriate parameters, and call getAllRates().
UPS¶
Example:
<?php
$rate = new \RocketShipIt\Rate('UPS');
$rate->setParameter('toCode', '90210'); // Customer Zip code
$package = new \RocketShipIt\Package('UPS');
$package->setParameter('weight', '5');
$rate->addPackageToShipment($package);
$response = $rate->getAllRates();
Where is the shipper’s zip code set?
When parameters are not present, RocketShipIt pulls them from your config.php file. If you want to specify a different shipper zip code you can specify it with the setParameter() function:
<?php
$rate = new \RocketShipIt\Rate('UPS');
$rate->setParameter('shipCode', '59579'); // This will override config.php setting
$rate->setParameter('toCode', '90210');
$package = new \RocketShipIt\Package('UPS');
$package->setParameter('weight', '5');
$rate->addPackageToShipment($package);
$response = $rate->getAllRates();
FedEx¶
To get rates for all available FedEx services you can do the same as above, just change the carrier:
<?php
$rate = new \RocketShipIt\Rate('fedex');
$rate->setParameter('toCode', '90210');
$package = new \RocketShipIt\Package('fedex');
$package->setParameter('weight', '5');
$rate->addPackageToShipment($package);
$response = $rate->getAllRates();
USPS¶
Example:
<?php
$rate = new \RocketShipIt\Rate('USPS');
$rate->setParameter('toCode','90210');
$package = new \RocketShipIt\Package('usps');
$package->setParameter('weight', '5');
$rate->addPackageToShipment($package);
$response = $rate->getAllRates();
DHL¶
To get rates for all available DHL services you can do:
<?php
$rate = new \RocketShipIt\Rate('DHL');
$rate->setParameter('toCode', '90210');
$package = new \RocketShipIt\Package('DHL');
$package->setParameter('weight', '5');
$rate->addPackageToShipment($package);
$response = $rate->getAllRates();
Canada Post¶
Example:
<?php
$rate = new \RocketShipIt\Rate('canada');
$rate->setParameter('shipCity','BELLEVILLE');
$rate->setParameter('shipCode','K8N5W6');
$rate->setParameter('toCode','94115');
$package = new \RocketShipIt\Package('canada');
$package->setParameter('weight','5');
$rate->addPackageToShipment($package);
$response = $rate->getAllRates();
Note
These will produce quite detailed information about a particular rate. Many RocketShipIt users prefer to use getSimpleRates() instead. See: Using Simple Rates.
Example Output¶
An example rate response might look like this:
Array
(
[RatingServiceSelectionResponse] => Array
(
[Response] => Array
(
[TransactionReference] => Array
(
[CustomerContext] => Array
(
[VALUE] => RocketShipIt
)
)
[ResponseStatusCode] => Array
(
[VALUE] => 1
)
[ResponseStatusDescription] => Array
(
[VALUE] => Success
)
)
[RatedShipment] => Array
(
[0] => Array
(
[Service] => Array
(
[Code] => Array
(
[VALUE] => 03
)
)
[RatedShipmentWarning] => Array
(
[VALUE] => Your invoice may vary from the displayed reference rates
)
[BillingWeight] => Array
(
[UnitOfMeasurement] => Array
(
[Code] => Array
(
[VALUE] => LBS
)
)
[Weight] => Array
(
[VALUE] => 5.0
)
)
[TransportationCharges] => Array
(
[CurrencyCode] => Array
(
[VALUE] => USD
)
[MonetaryValue] => Array
(
[VALUE] => 9.58
)
)
[ServiceOptionsCharges] => Array
(
[CurrencyCode] => Array
(
[VALUE] => USD
)
[MonetaryValue] => Array
(
[VALUE] => 0.00
)
)
[TotalCharges] => Array
(
[CurrencyCode] => Array
(
[VALUE] => USD
)
[MonetaryValue] => Array
(
[VALUE] => 9.58
)
)
[GuaranteedDaysToDelivery] => Array
(
[VALUE] =>
)
[ScheduledDeliveryTime] => Array
(
[VALUE] =>
)
[RatedPackage] => Array
(
[TransportationCharges] => Array
(
[CurrencyCode] => Array
(
[VALUE] => USD
)
[MonetaryValue] => Array
(
[VALUE] => 9.58
)
)
[ServiceOptionsCharges] => Array
(
[CurrencyCode] => Array
(
[VALUE] => USD
)
[MonetaryValue] => Array
(
[VALUE] => 0.00
)
)
[TotalCharges] => Array
(
[CurrencyCode] => Array
(
[VALUE] => USD
)
[MonetaryValue] => Array
(
[VALUE] => 9.58
)
)
[Weight] => Array
(
[VALUE] => 5.0
)
[BillingWeight] => Array
(
[UnitOfMeasurement] => Array
(
[Code] => Array
(
[VALUE] => LBS
)
)
[Weight] => Array
(
[VALUE] => 5.0
)
)
)
)
Fetching a single detailed rate¶
UPS¶
To get detailed rates on a single UPS service use the getRate() function:
<?php
$rate = new \RocketShipIt\Rate('UPS');
$rate->setParameter('toCode','90210');
$rate->setParameter('weight','5');
$response = $rate->getRate();
Why is there no service like “GROUND” set in this example?
RocketShipIt falls back to the defaults set in your config.php file when not specified directly using the setParameter() function.
FedEx¶
To get a detailed rate on a single FedEx service type you can do:
<?php
$rate = new \RocketShipIt\Rate('fedex');
$rate->setParameter('toCode', '90210');
$rate->setParameter('weight', '5');
// You can also set residential status
$rate->setParameter('residentialAddressIndicator', '1');
// The service type is explicitly set in this example
// If you have service in your config.php it would fall
// back to that if this wasn't present.
$rate->setParameter('service', 'GROUND_HOME_DELIVERY');
$response = $rate->getRate();
USPS¶
Note
USPS test servers only respond to pre-defined requests and will not respond properly. Call USPS and have them move you to the production servers before requesting USPS rates. This usually only takes a few minutes.
To get a detailed rate on a single USPS service type you can do:
<?php
$rate = new \RocketShipIt\Rate('USPS');
$rate->setParameter('toCode', '90210');
$rate->setParameter('service', 'PRIORITY');
$package = new \RocketShipIt\Package('USPS');
$package->setParameter('weight', '5.5');
// Optionally you can set dimensions
$package->setParameter('length', '1');
$package->setParameter('width', '2');
$package->setParameter('height', '3');
$rate->addPackageToShipment($package);
$response = $rate->getRate();
Note
These will produce quite detailed information about a particular rate. Many RocketShipIt users prefer to use getSimpleRates() instead. See: Using Simple Rates.
Fetching A Rate With Multiple Packages¶
Some carriers offer discounts when packages are shipped together in a shipment going to a single address. To fetch these rates RocketShipIt allows you to specify multiple packages in your request.
UPS¶
Here is an example of a shipment with two 5lb packages:
<?php
$rate = new \RocketShipIt\Rate('UPS');
$rate->setParameter('toCode', '90210');
// Here is the first package
$package = new \RocketShipIt\Package('UPS');
$package->setParameter('weight', '5');
$rate->addPackageToShipment($package);
// Here is the second package
$package = new \RocketShipIt\Package('UPS');
$package->setParameter('weight', '5');
$rate->addPackageToShipment($package);
$response = $rate->getAllRates();
FedEx¶
Here is an example of a shipment with two 5lb packages using getSimpleRates():
<?php
$rate = new \RocketShipIt\Rate('fedex');
$rate->setParameter('toCode', '90210');
$rate->setParameter('residentialAddressIndicator','1');
$rate->setParameter('service', 'GROUND_HOME_DELIVERY');
$package = new \RocketShipIt\Package('fedex');
$package->setParameter('weight', '5');
$rate->addPackageToShipment($package);
$package = new \RocketShipIt\Package('fedex');
$package->setParameter('weight', '5');
$rate->addPackageToShipment($package);
$response = $rate->getSimpleRates();
USPS¶
Here is an example of a shipment with two 5lb packages with dimensions using getRate():
<?php
$rate = new \RocketShipIt\Rate('USPS');
$rate->setParameter('toCode', '90210');
$rate->setParameter('service', 'PARCEL');
$package = new \RocketShipIt\Package('USPS');
$package->setParameter('weight', '5');
$package->setParameter('length', '1');
$package->setParameter('width', '2');
$package->setParameter('height', '3');
$rate->addPackageToShipment($package);
$package = new \RocketShipIt\Package('USPS');
$package->setParameter('weight', '5');
$package->setParameter('length', '1');
$package->setParameter('width', '2');
$package->setParameter('height', '3');
$rate->addPackageToShipment($package);
$response = $rate->getRate();
DHL¶
Example:
<?php
$rate = new \RocketShipIt\Rate('DHL');
$rate->setParameter('shipCity', 'San Francisco');
$rate->setParameter('shipCode', '94110');
$rate->setParameter('toCode', '59715');
$package = new \RocketShipIt\Package('dhl');
$package->setParameter('weight', '5');
$rate->addPackageToShipment($package);
$package = new \RocketShipIt\Package('dhl');
$package->setParameter('weight', '5');
$rate->addPackageToShipment($package);
$response = $rate->getAllRates();
Services¶
To specify the service you use the service parameter:
<?php
$rate->setParameter('service','GROUND_HOME_DELIVERY');
UPS¶
Value | Description |
---|---|
01 | UPS Next Day Air |
02 | UPS Second Day Air |
03 | UPS Ground |
07 | UPS Worldwide Express |
08 | UPS Worldwide Expedited |
11 | UPS Standard |
12 | UPS Three-Day Select |
13 | Next Day Air Saver |
14 | UPS Next Day Air Early AM |
54 | UPS Worldwide Express Plus |
59 | UPS Second Day Air AM |
65 | UPS Saver |
FedEx¶
Value | Description |
---|---|
EUROPE_FIRST_INTERNATIONAL_PRIORITY | FedEx Europe First International Priority® |
FEDEX_1_DAY_FREIGHT | FedEx 1Day® Freight |
FEDEX_2_DAY | FedEx 2Day® |
FEDEX_2_DAY_AM | FedEx 2Day® A.M. |
FEDEX_2_DAY_FREIGHT | FedEx 2Day® Freight |
FEDEX_3_DAY_FREIGHT | FedEx 3Day® Freight |
FEDEX_EXPRESS_SAVER | FedEx Express Saver® |
FEDEX_FIRST_FREIGHT | FedEx First® Freight |
FEDEX_FREIGHT_ECONOMY | FedEx Freight® Economy |
FEDEX_FREIGHT | FedEx Freight |
FEDEX_NATIONAL_FREIGHT | FedEx National Freight |
FEDEX_FREIGHT_PRIORITY | FedEx Freight® Priority |
FEDEX_GROUND | FedEx Ground® |
FIRST_OVERNIGHT | FedEx First Overnight® |
GROUND_HOME_DELIVERY | FedEx Home Delivery® |
INTERNATIONAL_ECONOMY | FedEx International Economy® |
INTERNATIONAL_ECONOMY_FREIGHT | FedEx International Economy® Freight |
INTERNATIONAL_FIRST | FedEx International First® |
INTERNATIONAL_PRIORITY | FedEx International Priority® |
INTERNATIONAL_PRIORITY_FREIGHT | FedEx International Priority® Freight |
PRIORITY_OVERNIGHT | FedEx Priority Overnight® |
SMART_POST | FedEx SmartPost® |
STANDARD_OVERNIGHT | FedEx Standard Overnight® |
USPS¶
- FIRST CLASS
- PRIORITY
- PRIORITY COMMERCIAL
- EXPRESS
- EXPRESS COMMERCIAL
- EXPRESS SH
- EXPRESS SH COMMERCIAL
- EXPRESS HFP
- EXPRESS HFP
- COMMERCIAL
- BPM
- PARCEL
- MEDIA
- LIBRARY
- ALL
- ONLINE
Stamps.com¶
Value | Description |
---|---|
US-FC | USPS First-Class Mail |
US-MM | USPS Media Mail |
US-PP | USPS Parcel Post |
US-PM | USPS Priority Mail |
US-XM | USPS Express Mail |
US-EMI | USPS Express Mail International |
US-PMI | USPS Priority Mail International |
US-FCI | USPS First Class Mail International |
US-CM | USPS Critical Mail |
US-PS | USPS Parcel Select |
US-LM | USPS Library Mail |
Signature Options¶
FedEx¶
Signature Types:
Value | Description |
---|---|
ADULT | Adult signature required |
DIRECT | Signature Required |
INDIRECT | Signature may be required (default) |
NO_SIGNATURE_REQUIRED | Signature not required |
SERVICE_DEFAULT | Default |
Here is an example of a shipment requiring a direct signature:
<?php
$rate = new \RocketShipIt\Rate('fedex');
$rate->setParameter('toCode', '90210');
$rate->setParameter('weight', '5');
$rate->setParameter('signatureType', 'DIRECT');
$response = $rate->getAllRates();
Insurance¶
UPS¶
Adding insurance:
<?php
$rate = new \RocketShipIt\Rate('UPS');
$package = new \RocketShipIt\Package('UPS');
$package->setParameter('weight', '5');
$package->setParameter('insuredCurrency', 'USD');
$package->setParameter('insuredValue', '700');
$rate->addPackageToShipment($package);
$rate->setParameter('toCode', '90210');
$response = $rate->getAllRates();
FedEx¶
Adding insurance:
<?php
$rate = new \RocketShipIt\Rate('fedex');
$rate->setParameter('toCode', '90210');
$rate->setParameter('weight', '5');
$rate->setParameter('insuredCurrency', 'USD');
$rate->setParameter('insuredValue', '200');
$response = $rate->getAllRates();
Stamps.com¶
Adding insurance:
<?php
$rate = new \RocketShipIt\Rate('stamps');
$rate->setParameter('toCode', '94110');
$rate->setParameter('weight', '5');
$rate->setParameter('length', '5');
$rate->setParameter('width', '5');
$rate->setParameter('height', '5');
$rate->setParameter('insuredValue', '100');
$response = $rate->getAllRates();
DHL¶
Adding insurance:
<?php
$rate = new \RocketShipIt\Rate('DHL');
$rate->setParameter('shipCity', 'San Francisco');
$rate->setParameter('shipCode', '94110');
$rate->setParameter('toCode', '59715');
$rate->setParameter('weight', '5');
$rate->setParameter('insuredValue', '100.00');
$rate->setParameter('insuredCurrency', 'USD');
$response = $rate->getAllRates();
Canada Post¶
Adding insurance:
<?php
$rate = new \RocketShipIt\Rate('canada');
$rate->setParameter('shipCity', 'BELLEVILLE');
$rate->setParameter('shipCode', 'K8N5W6');
$rate->setParameter('toCode', '94115');
$rate->setParameter('weight', '5');
$rate->setParameter('insuredValue', '500.00');
$response = $rate->getAllRates();