Shipping costs based product category
I have different product categories.
Categories 1,2,3,6,7 have a shipping flat rate of 10, categories 4 and 5 have a shipping flat rate of 0. If there are only products of category 4 and/or 5 in the cart the shipping should be 0. If there are products from category 4 and/or 5 and one or more of the other categories, then the total shipping should be 10.
Can you please give me some hints how to implement this? Thanks for any help in advance.