Lewis Hamilton has earned his first trophy for Ferrari after producing a masterful driver to win the Sprint in Shanghai.