I've just done a test in version 0.28.181.40d, and I can confirm that Z-levels do count toward distance. My test setup as as follows:
1. A Mason's workshop on Z=149
2. Around the Mason's workshop, a 9x9 stone stockpile (with the center 3x3 occupied by the workshop itself, resulting in 3 concentric rings of distance 2, 3, and 4)
3. 3 Z-levels directly beneath the center of the workshop, a 3x3 stone stockpile
4. 15 Z-levels directly beneath the center of the workshop, a 3x3 stone stockpile
5. Mason's workshop set to Make Rock Blocks on repeat
The stones were used up in the following order:
1. A stone from the outer edge of the stockpile (because the mason was standing by the wagon)
2. The innermost ring around the workshop (distance 2)
3. The 9 stones 3 Z-levels beneath the workshop and the middle ring around the workshop (distance 3)
4. The outer ring around the workshop (distance 4)
5. The 9 stones 15 z-levels beneath the workshop (distance 15)
Thus, the material's effective distance is the maximum of the X-distance, the Y-distance, and the Z-distance, as if the "eligible item zone" was gradually expanding outward in a cube shape until it found something. It doesn't calculate actual linear distance, since that would require using multiplication and square roots (which are very expensive calculations when you're potentially doing them against tens of thousands of items per job).
You're welcome to repeat this test in version 0.40.05, though I'm willing to bet that the results will be the same.