Creating a Shipment with Multiple Packages

UPS

RocketShipIt™ allows developers to send multiple packages to a single shipment. First let’s look at an example of a single package shipment.:

<?php
$shipment = new \RocketShipIt\Shipment('UPS');

$shipment->setParameter('toCompany', 'John Doe');
$shipment->setParameter('toPhone', '1231231234');
$shipment->setParameter('toAddr1', '101 W Main');
$shipment->setParameter('toCity', 'Bozeman');
$shipment->setParameter('toState', 'MT');
$shipment->setParameter('toCode', '59715');

$package = new \RocketShipIt\Package('UPS');
$package->setParameter('length','5');
$package->setParameter('width','5');
$package->setParameter('height','5');
$package->setParameter('weight','5');

$shipment->addPackageToShipment($package);

$label = $shipment->submitShipment();

print_r($label);

This part of the code creates a new package and describes the package’s length, width, height and weight. The addPackageToShipment(); function then adds this newly created package to the shipment.:

<?php
$package = new \RocketShipIt\Package('UPS');
$package->setParameter('length','5');
$package->setParameter('width','5');
$package->setParameter('height','5');
$package->setParameter('weight','5');

$shipment->addPackageToShipment($package);

To add another package we simple create another package object and add it like we did above. We will call this $package2 for clarity.:

<?php
$package2 = new \RocketShipIt\Package('UPS');
$package2->setParameter('length','5');
$package2->setParameter('width','5');
$package2->setParameter('height','5');
$package2->setParameter('weight','5');

$shipment->addPackageToShipment($package2);

When you are ready to submit the final shipment to UPS simply call the submitShipment(); function.:

<?php
$label = $shipment->submitShipment();

print_r($label);

Note

UPS currently has a limit of 999 packages that can be sent with a single shipment request.

FedEx

Example:

<?php

$shipment = new \RocketShipIt\Shipment('fedex');

$shipment->setParameter('toCompany', 'John Doe');
$shipment->setParameter('toName', 'John Doe');
$shipment->setParameter('toPhone', '1231231234');
$shipment->setParameter('toAddr1', '111 W Legion');
$shipment->setParameter('toCity', 'Whitehall');
$shipment->setParameter('toState', 'MT');
$shipment->setParameter('toCode', '59759');
$shipment->setParameter('packageCount', '2');
$shipment->setParameter('sequenceNumber', '1');

$shipment->setParameter('length', '5');
$shipment->setParameter('width', '5');
$shipment->setParameter('height', '5');
$shipment->setParameter('weight','25');

$response = $shipment->submitShipment();
$shipmentId = $response['trk_main'];

$label1 = $response['pkgs'][0]['label_img'];

$shipment = new \RocketShipIt\Shipment('fedex');

$shipment->setParameter('toCompany', 'John Doe');
$shipment->setParameter('toName', 'John Doe');
$shipment->setParameter('toPhone', '1231231234');
$shipment->setParameter('toAddr1', '111 W Legion');
$shipment->setParameter('toCity', 'Whitehall');
$shipment->setParameter('toState', 'MT');
$shipment->setParameter('toCode', '59759');
$shipment->setParameter('packageCount', '2');
$shipment->setParameter('sequenceNumber', '2');
$shipment->setParameter('shipmentIdentification', $shipmentId);

$shipment->setParameter('length', '5');
$shipment->setParameter('width', '5');
$shipment->setParameter('height', '5');
$shipment->setParameter('weight','15');

$response = $shipment->submitShipment();

$label2 = $response['pkgs'][0]['label_img'];
$charges = $response['charges'];
print_r($response);

DHL

Example:

<?php
$shipment = new \RocketShipIt\Shipment('dhl');

$shipment->setParameter('shipper', 'RocketShipIt');
$shipment->setParameter('shipAddr1', '1 Zoo Rd');
$shipment->setParameter('shipCity', 'San Francisco');
$shipment->setParameter('shipState', 'California');
$shipment->setParameter('shipCode', '94132');
$shipment->setParameter('shipCountry', 'US');

$shipment->setParameter('toCompany', 'San Francisco Zoo');
$shipment->setParameter('toAddr1', '1 Zoo Rd');
$shipment->setParameter('toCity', 'San Francisco');
$shipment->setParameter('toState', 'California');
$shipment->setParameter('toCode', '94132');
$shipment->setParameter('toCountry', 'US');

$shipment->setParameter('toName', 'Mark Sanborn');
$shipment->setParameter('toPhone', '1234567');

$shipment->setParameter('service', 'D');

$package = new \RocketShipIt\Package('dhl');
$package->setParameter('weight', '7');
$shipment->addPackageToShipment($package);


$package = new \RocketShipIt\Package('dhl');
$package->setParameter('weight', '8');
$shipment->addPackageToShipment($package);

$response = $shipment->submitShipment();