PHP code example of justinhook / royal-mail-price-calculator
1. Go to this page and download the library: Download justinhook/royal-mail-price-calculator library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
justinhook / royal-mail-price-calculator example snippets
RoyalMailPriceCalculator\Calculator;
use \RoyalMailPriceCalculator\Package;
use \RoyalMailPriceCalculator\Services\GuaranteedByOnePmService;
use \RoyalMailPriceCalculator\Services\FirstClassService;
$calculator = new Calculator();
$package = new Package();
$package->setDimensions(15, 15, 0.4);
$package->setWeight(90);
$calculator->setServices(array(new FirstClassService(), new GuaranteedByOnePmService()));
foreach ($calculator->calculatePrice($package) as $calculated)
{
echo $calculated['service']->getName() . "\n";
foreach ($calculated['prices'] as $price) {
echo " → £{$price['price']} (Compensation: £{$price['compensation']})\n";
}
echo "\n";
}