How to record a new shipping cost and totals cost for a registered order?

//1:
update_post_meta( $order_id, '_order_shipping', '313' );

//2:    
$order = new WC_Order( $order_id );             
$order->calculate_totals();
$order->save();

After executing code 2, code 1 becomes ineffective!