According to Aufbau principle, orbitals are filled in the increasing order of energy . That is the orbitals having lower energy will fill first. So 1st filling of 1s orbital takes place then 2s then 2p , 3s , 3p and after that 4s and follows 3d.
So d- orbital will be filled when all these orbitals are fully occupied. That is when 1s, 2s , 2p , 3s , 3p and 4s are fully filled with electrons then filling of electrons takes places in 3d orbital. However there are cases in which 4s orbital will take electron after 3d orbital in caeses of half filled or fully filled orbitals.