Go to WooCommerce->Settings->Shipping tab and create a shipping class for sample.
Set the shipping cost for sample by creating shipping method.
Then assign the shipping class for sample. Go to the product details page and click on the Sample Product tab. Select the desired sample shipping class from the shipping class dropdown.
Then the shipping class will be calculated automatically for sample based on shipping address.