// This \Closure will find actual handler by date from handler's extra data
$selector = function ($handlers, PackageInterface $package) {
    /** @var CalculatorInterface $currentHandler */
    $currentHandler = null;
    $currentDate = null;
    /** @var CalculatorHandlerInterface $handler */
    foreach ($handlers as $handler) {
        $extraData = $handler->get('extra_data');
        $date = new \DateTime($extraData['date']);
        if ($package->getCalculationDate() >= $date && (is_null($currentHandler) || $date > $currentDate)) {
            $currentHandler = $handler;
        }
    }
    return $currentHandler;
};
$calculator = new SelectiveCalculator(['handlers' => [AsendiaCalculatorHandler::create($config1), DhlCalculatorHandler::create($config2)], 'selector' => $selector]);
$weight = new Weight();
$weight->setValue(10);
$weight->setUnit('lb');
$dimensions = new Dimensions();
$dimensions->setLength(10);
$dimensions->setWidth(10);
$dimensions->setHeight(10);
$dimensions->setUnit('in');
$senderAddress = new Address();
$senderAddress->setCountryCode('USA');
$recipientAddress = new Address();
$recipientAddress->setCountryCode('RUS');
$package = new Package();
// Change this date to calculate shipping by other calculator.
// For example, `2015-12-12`.
<?php

use EsteIt\ShippingCalculator\Calculator\BaseCalculator;
use EsteIt\ShippingCalculator\CalculatorHandler\DhlCalculatorHandler;
use EsteIt\ShippingCalculator\Model\Weight;
use EsteIt\ShippingCalculator\Model\Dimensions;
use EsteIt\ShippingCalculator\Model\Address;
use EsteIt\ShippingCalculator\Model\Package;
include_once __DIR__ . '/../vendor/autoload.php';
$config = (include __DIR__ . '/../src/Resources/DHL/ExportExpressWorldWide/tariff_2015_08_25_usa.php');
$calculator = new BaseCalculator(['handler' => DhlCalculatorHandler::create($config)]);
$weight = new Weight();
$weight->setValue(10);
$weight->setUnit('lb');
$dimensions = new Dimensions();
$dimensions->setLength(10);
$dimensions->setWidth(10);
$dimensions->setHeight(10);
$dimensions->setUnit('in');
$senderAddress = new Address();
$senderAddress->setCountryCode('USA');
$recipientAddress = new Address();
$recipientAddress->setCountryCode('RUS');
$package = new Package();
$package->setCalculationDate(new \DateTime());
$package->setWeight($weight);
$package->setDimensions($dimensions);
$package->setSenderAddress($senderAddress);
$package->setRecipientAddress($recipientAddress);
$result = $calculator->calculate($package);
var_dump($result->getTotalCost());
 public function testCreate()
 {
     $calculator = DhlCalculatorHandler::create(['zone_calculators' => [['name' => 1, 'weight_prices' => [['weight' => 10, 'price' => 21.4]]]], 'import_countries' => [['code' => 'USA', 'zone' => 1]], 'export_countries' => [['code' => 'USA']], 'mass_unit' => 'lb', 'dimensions_unit' => 'in', 'maximum_dimensions' => ['length' => 40, 'width' => 40, 'height' => 40], 'maximum_weight' => 60]);
     $this->assertInstanceOf('EsteIt\\ShippingCalculator\\CalculatorHandler\\DhlCalculatorHandler', $calculator);
 }