When Formula Chemicals came to me at Weidenhammer in early 2019, their CEO had one ask above all others, “I need to be able to send shipments in containers.”
The purpose of this blog post is not to detail the technical work implemented but instead to go over how I approached writing a very complex feature for a client.
Initially, I thought like all shipping; I would just use an API and send it data to get a quote back. Sadly, this was not the case, as almost no shipper has a robust API with endpoints to quickly reach out to in this way. This information meant I started architecting out the implementation to be built in house.
At a very high level this system needed to accomplish the following:
- Track 20′ Containers or 40′ Containers
- Do not go over the Kilogram limit per container
- Do not go over the cubic meter volumetric numbers
- Allow the entry of rates per shipping lane
- Follow all laws for shipping containers of goods
There were so many more considerations, and in hindsight, this was one of the most complicated things I would build, I have no shame in admitting it went overestimate. No one I knew was an expert in international shipping or even working with containers.
The client had decided who they were going to use for shipping, but I wanted this extension to be method agnostic, the company could just upload rate sheets based on shipping lane. Using extension attributes and custom tables, we would track everything added to the cart and continuously calculate the rates as the order was placed.
So putting this as simply as possible, container shipping is done in two ways. Less than container load (LCL) and Full container load (FCL), one is calculated more or less in kilograms (FCL), and one is measured in cubic meters used (LCL). Containers come in two sizes, 20′ and 40′, but a 40′ container is not double in size of a 20′ container.
For this blog, a 20′ container will hold 25,000kg and has a volumetric size of 33 cubic meters. A 40′ container will hold 27,600kg and has a volumetric capacity of 66 cubic meters. Notice the volume increased by 100%, but the weight limit increased by only 10.4%. Those limits are required by container ships.
A brief aside, I did have one advantage when I was a younger man. I worked on a Schooner in Key West Florida, while there I got my 100-ton Captain’s license. Having done that, I learned many of the international laws around ships, as well as how the Panama Canal worked, so I knew why these limits existed, but I admit I did not see the limit off the top of my head.
So the basic system involved how many kilograms ordered; As well as calculating how the volume used. Using that data, we could calculate how many containers were required. That data allowed our system to work without caring how the dock would pack the box, though I did keep track of what was in what container. I did this because I knew the Bill of Lading usually needs to detail what exactly is in what container as Captains could be inspected anytime they cross into a countries waters. For example, the United States Coast Guard will stop many ships on the high seas in our seas and run a quick inspection of the vessel, and it’s cargo manifest.
Knowing all of the data ahead of time, the customer lands on a Magento checkout page, and shipping is calculated. I have mentioned “shipping lane” a few times so far. What a shipping lane is more or less is an origin port and destination port, where cargo shippers usually charge rates for specific shipping lanes. As a rule, this system did not take multiple origins or multiple destinations into consideration; instead, assuming all products will come from the same source and go to the same destination. How a company gets its goods from the port to their company was not a consideration.
So, for example, if a customer is shipping 52,900kg of goods using 144 cubic meters of space, from Shanghai to Paris, the shipper will have a rate applied to that lane, a standard for the LCL and a rate per container of each size. Our system will aggregate all of that data and return a quote for shipping allowing the customer to pay for in advance. The rate could change between before the goods ship, at which point the CSR from the company will need to update the customer.
All of this was working after it was written, that is until some tariffs were applied from certain countries. New customization was required to allow that to be added into the calculation as a separate line item while adding that I also added a feature to give the company a “Packing sheet,” which can be sent to the customer detailing what would be in what container. This packing sheet was elementary as all of the data was present, but it provided a client win.
As you can see, it is possible using Magento to architect your API and use it internally. The client has considered making the API a public endpoint as another revenue stream; I feel the work on this has just begun.