This package is abandoned and no longer maintained. No replacement package was suggested.

Calculate postage costs for a parcel

v1.1.0 2020-11-23 11:52 UTC

This package is auto-updated.

Last update: 2021-01-05 09:05:11 UTC


Calculates price for UK postal services


PHP 7.0+


$ composer require rairlie/postage-calculator


use Rairlie\PostageCalculator\PostageCalculator;
use Rairlie\PostageCalculator\ParcelForce;

// Calculate postage for a Royal Mail parcel
$postageCalculator = new PostageCalculator();
$price = $postageCalculator
        450, // Weight in grams
        [10, 22, 8] // Dimensions in cm - length, width, depth
// Calculate postage for a Parcelforce parcel
$price = $postageCalculator
        450, // Weight in grams

Parcelforce parcels can be sent by four methods:

  • ParcelForce::METHOD_COLLECT - Parcel to be collected from a pick-up address
  • ParcelForce::METHOD_DROP_POST_OFFICE - Parcel to be dropped at a PostOffice
  • ParcelForce::METHOD_DROP_DEPOT - Parcel to be dropped at a depot
  • ParcelForce::METHOD_DEPOT_TO_DEPOT - Parcel to be dropped at and collected from a depot


The prices are derived from configuration files in src/Defaults:


The format should be fairly self-explanatory, and prices are correct as of January 2018. If you need to customise them, for example to load them from a DB or to facilitate unit testing, you can pass your own price configs into the constructor:

$postageCalculator = new PostageCalculator([
    PostageCalculator::SERVICE_ROYAL_MAIL => $myRoyalMailPrices,
    PostageCalculator::SERVICE_PARCELFORCE_24 => $myParcelForce24Prices,
    PostageCalculator::SERVICE_PARCELFORCE_48 => $myParcelForce48Prices,


The following exceptions may be thrown:

  • ParcelTooHeavyException - the parcel is too heavy to send with the service
  • ParcelTooLargeException - the parcel is too large (dimensions) to send with the service
  • MethodUnavailableException - its not possible to use the specified delivery method to send this parcel (Parcelforce only)