There are only 6 possible configurations of the hats. You would work it out like this to eliminate the two configurations that won't work for you.
if h(3) = h(2) we can know from this equation that we can eliminate the color combination of BWWB and WBBW. Therefore the color will be WBWB or BWBW
Who would be the first person would need to be the one who calls out the color of his hat? This would be person C. Person C has done the math and he has determined that he must be wearing the opposite color of the hat from the person that is directly in front of him. If B is wearing the White hat then that means that C will be wearing the Black colored hat.
When C looks at B and D says nothing at all, then C knows that he must have the opposite color of the hat that B is wearing. Therefore, C would be the one to guess the color of the hat and he would say Black.