Example #1
0
 /**
  * Get a quote for a shippment of $items to $address. $options could be changed for different use cases.
  *
  * @param Address $address
  * @param array $items [['sku' => 'CAPTRACKERBLUE', 'quantity' => 3]]
  * @param array $options for example: ["currency" => "USD", "groupBy" => "all", "canSplit" => 1, "warehouseArea" => "US"]
  *
  * @return array
  */
 public function quote(Address $address, $items = [], $options = [])
 {
     if (count($options) == 0) {
         $options = ["currency" => "USD", "groupBy" => "all", "canSplit" => 1, "warehouseArea" => "US"];
     }
     $json = json_encode(['options' => $options, 'order' => ['shipTo' => $address->asArray(), 'items' => $items]]);
     return $this->post('rate', [], $json);
 }
Example #2
0
 public function testRates()
 {
     $rate = new Rate();
     $address = Address::createFromArray(["address1" => "6501 Railroad Avenue SE", "address2" => "Room 315", "address3" => "", "city" => "Snoqualmie", "postalCode" => "85283", "region" => "WA", "country" => "US", "isCommercial" => 0, "isPoBox" => 0]);
     $shippingInfo = $rate->quote($address, [['sku' => 'CAPTRACKERBLUE', 'quantity' => 3]]);
     foreach ($shippingInfo['rates'][0]['serviceOptions'] as $shippingRate) {
         echo $shippingRate['serviceLevelName'] . ' | ' . $shippingRate['shipments'][0]['carrier']['name'];
         echo ' => ' . $shippingRate['shipments'][0]['cost']['amount'];
         echo "\n\t" . $shippingRate['shipments'][0]['carrier']['description'];
         echo "\n\t" . $shippingRate['shipments'][0]['expectedDeliveryMaxDate'];
         echo "\n";
     }
 }