SQL Code to illustrate - (This is T-SQL and is SQL Server friendly, but i didn't have any mysql handy. The last query should with tiny modifications (to suit your table names) work nicely in MySQL as well.
My logic is to find the most recent company_order for each product_id. Once i have that i can just join the company_order_id to company_order, and i have the shipment_id for each most-recent company_order per product_id
DROP TABLE #shipment
DROP TABLE #company_order
DROP TABLE #company_order_item
CREATE TABLE #shipment
(
shipment_id INT ,
shipping_date INT
) ;
CREATE TABLE #company_order
(
company_order_id INT ,
shipment_id INT ,
company_id INT
) ;
CREATE TABLE #company_order_item
(
company_order_item_id INT ,
company_order_id INT ,
product_id INT
) ;
INSERT INTO #shipment
( shipment_id , shipping_date )
VALUES
( 1 , 1 ),
( 2 , 2 ),
( 3 , 3 )
INSERT INTO #company_order
( company_order_id , shipment_id , company_id )
VALUES
( 1 , 1 , 1 ),
( 2 , 2 , 1 ),
( 3 , 3 , 1 )
INSERT INTO #company_order_item
( company_order_item_id , company_order_id , product_id )
VALUES
( 1 , 1 , 1 ) ,
( 2 , 1 , 2 ),
( 2 , 2 , 2 ),
( 1 , 1 , 3 ),
( 1 , 3 , 4 )
SELECT
product_id ,
shipment_id
FROM
(
SELECT
product_id ,
MAX(company_order_id) AS company_order_id
FROM
#company_order_item
GROUP BY
product_id
) AS MostRecentProductInOrder
INNER JOIN #company_order
ON MostRecentProductInOrder.company_order_id = #company_order.company_order_id