protected function buildRateRequest()
{
$rating = new Child('RatingServiceSelectionRequest');
$request = new Child('Request');
$transaction = new Child('TransactionReference');
$pickup = new Child('PickupType');
$shipment = new Child('Shipment');
$customer = new Child('CustomerContext', 'Rating and Service');
$xpci = new Child('XpciVersion', '1.0');
$requestAction = new Child('RequestAction', 'Rate');
$requestOption = new Child('RequestOption', 'Shop');
$transaction->addChild($customer)->addChild($xpci);
$request->addChild($transaction)->addChild($requestAction)->addChild($requestOption);
$pickup->addChild(new Child('Code', $this->pickupType))->addChild(new Child('Description', self::$pickupTypes[$this->pickupType]));
$shipment->addChild(new Child('Description', 'Rate'));
$shipper = new Child('Shipper');
$shipper->addChild(new Child('ShipperNumber', $this->userId));
$shipTo = new Child('ShipTo');
$shipFrom = new Child('ShipFrom');
if (null !== $this->shipTo['CompanyName']) {
$shipTo->addChild(new Child('CompanyName', $this->shipTo['CompanyName']));
}
if (null !== $this->shipFrom['CompanyName']) {
$shipFrom->addChild(new Child('CompanyName', $this->shipFrom['CompanyName']));
}
$shipToAddress = new Child('Address');
foreach ($this->shipTo as $key => $value) {
if ($key !== 'CompanyName') {
$shipToAddress->addChild(new Child($key, $value));
}
}
$shipFromAddress = new Child('Address');
foreach ($this->shipFrom as $key => $value) {
if ($key !== 'CompanyName') {
$shipFromAddress->addChild(new Child($key, $value));
}
}
$shipTo->addChild($shipToAddress);
$shipFrom->addChild($shipFromAddress);
$shipper->addChild($shipFromAddress);
$service = new Child('Service');
$service->addChild(new Child('Code', $this->service))->addChild(new Child('Description', self::$services[$this->service]));
$package = new Child('Package');
$packageType = new Child('PackagingType');
$packageType->addChild(new Child('Code', $this->packageType))->addChild(new Child('Description', self::$packagingTypes[$this->packageType]));
$package->addChild($packageType)->addChild(new Child('Description', 'Rate'));
if (null !== $this->dimensions['Length'] && null !== $this->dimensions['Width'] && null !== $this->dimensions['Height']) {
$dimensions = new Child('Dimensions');
$unit = new Child('UnitOfMeasurement');
$unit->addChild(new Child('Code', $this->dimensions['UnitOfMeasurement']));
$dimensions->addChild($unit)->addChild(new Child('Length', $this->dimensions['Length']))->addChild(new Child('Width', $this->dimensions['Width']))->addChild(new Child('Height', $this->dimensions['Height']));
$package->addChild($dimensions);
}
$weight = new Child('PackageWeight');
$unit = new Child('UnitOfMeasurement');
$unit->addChild(new Child('Code', $this->weight['UnitOfMeasurement']));
$weight->addChild($unit)->addChild(new Child('Weight', $this->weight['Weight']));
$package->addChild($weight);
$shipment->addChild($shipper)->addChild($shipTo)->addChild($shipFrom)->addChild($service)->addChild($package);
$rating->addChild($request)->addChild($pickup)->addChild($shipment);
$this->rateRequest->addChild($rating);
}